﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jayden.Dll.ECMAScript
{
	public interface Statement
	{
		void RenderStatement(int level, StringBuilder builder);
	}

	public class StatementList : List<Statement>, Statement
	{
		public virtual void RenderStatement(int level, StringBuilder builder)
		{
			foreach (Statement statement in this)
				statement.RenderStatement(level, builder);
		}

		public static void AppendSpacing(int level, string spacing, StringBuilder builder)
		{
			for (int c = 0; c < level; c++)
				builder.Append(spacing);
		}
	}
	public class Empty : Statement
	{
		public static readonly Empty Instance = new Empty();
		public void RenderStatement(int level, StringBuilder builder)
		{
			StatementList.AppendSpacing(level, "\t", builder);
			builder.AppendLine(";");
		}
	}
	public class ExpressionStatement : Statement
	{
		private Expression m_Expression;
		public ExpressionStatement(Expression expression) { m_Expression = expression; }
		public void RenderStatement(int level, StringBuilder builder)
		{
			StatementList.AppendSpacing(level, "\t", builder);
			m_Expression.RenderExpression(builder);
			builder.AppendLine(";");
		}
	}
}
